//! 泛微OA的url path部分。
//!
//! 定义OA uri的路径的枚举，生成完成的   uri。
//! 

use crate::oa_path::*;
pub(self) use OaPath::*;


pub enum OaPath {
    RegisterToken,
    Token,
    ToDoWorkflowRequestList,
    WorkflowRequest,
    WorkflowRequestLog
}

/// 生成完成的URL，用于请求数据。
///
/// base_uri 为http/https形式开头的域名或者是ip地址，**一定要以`/`结尾。**，例如 `http://127.0.0.1/`。
///
/// pat: enum Path 中的限定。
///
/// # Example
///
/// ```rust
/// use weaver_oa::uri::{OaPath, generate_uri};
///
/// let mut h = "http://127.0.0.1/".to_string();
///
/// h = generate_uri(h, OaPath::Token);
///
/// assert!(h.ends_with("/applytoken"));
/// ```
pub fn generate_uri(mut base_uri: String, pat: OaPath) -> String {
    let u = match pat {
        RegisterToken => REGISTER_TOKEN_PATH,
        Token => TOKEN_PATH,
        ToDoWorkflowRequestList => TO_DO_WORKFLOW_REQUEST_LIST,
        WorkflowRequest => WORKFLOW_REQUEST,
        WorkflowRequestLog => WORKFLOW_REQUEST_LOG,
    };

    base_uri.push_str(&u);
    return base_uri;
}

#[cfg(test)]
mod tests {
    use super::super::oa_path::{REGISTER_TOKEN_PATH, TOKEN_PATH};
    use super::*;

    #[test]
    fn test_generate_uri() {
        let mut h = "http://127.0.0.1/".to_string();
        h = generate_uri(h, OaPath::Token);
        assert!(h.ends_with("/applytoken"));
        let b = format!("http://127.0.0.1/{TOKEN_PATH}");

        assert!(h.eq(&b));
        let b = format!("http://127.0.0.1/{REGISTER_TOKEN_PATH}");
        assert!(h.ne(&b));
    }
}
